﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace GandA.Web.UI.Controls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:Button runat=server></{0}:Button>")]
    [ToolboxBitmap(typeof(System.Web.UI.WebControls.Button))]
    public class Button : System.Web.UI.WebControls.Button
    {
        #region Propiedades
        public string Params
        {
            get { return ViewState["_Params"] == null ? string.Empty : ViewState["_Params"].ToString(); }
            set { ViewState["_Params"] = value; this.Attributes.Add("Params", value); }
        }
        #endregion

        protected override void OnPreRender(EventArgs e)
        {
            bool linkIncluded = false;
            foreach (Control c in Page.Header.Controls)
            {
                if (c.ID == "StyleControls")
                {
                    linkIncluded = true;
                }
            }
            if (!linkIncluded)
            {
                HtmlGenericControl csslink = new HtmlGenericControl("link");
                csslink.ID = "StyleControls";
                csslink.Attributes.Add("href",
                                       Page.ClientScript.GetWebResourceUrl(this.GetType(), "GandA.Web.UI.Controls.Controls.css"));
                csslink.Attributes.Add("type", "text/css");
                csslink.Attributes.Add("rel", "stylesheet");
                Page.Header.Controls.Add(csslink);
            }

            base.OnPreRender(e);
        }
    }
}
